package it.univaq.mwt.facade;

import java.io.IOException;

import it.univaq.mwt.business.FilesService;
import it.univaq.mwt.exceptionmonitor.LivelloEx;
import it.univaq.mwt.exceptionmonitor.WishListrException;
import it.univaq.mwt.exceptionmonitor.WishlistUserException;
import it.univaq.mwt.exceptionmonitor.WishlistrMessage;
import it.univaq.mwt.log.LivelloLog;
import it.univaq.mwt.log.LogManager;
import it.univaq.mwt.model.bean.FilesBeanRemote;
import it.univaq.mwt.model.entity.Files;
import it.univaq.mwt.model.entity.Gift;

public class FacadeFiles implements FilesService,LivelloEx, LivelloLog {

	private FilesBeanRemote fbr;
	
	public FilesBeanRemote getFbr() {
		return fbr;
	}

	public void setFbr(FilesBeanRemote fbr) {
		this.fbr = fbr;
	}

	public FacadeFiles(FilesBeanRemote fbr) {
		super();
		this.fbr = fbr;
	}

	
	public Files createFiles(Files file,Gift gift){
		
		Files newFile = null;
		try {
			try {
				newFile = fbr.createFile(file,gift);
			} catch (WishlistrMessage e) {
				LogManager.getIstance().scrivi("FacadeGift - createFiles :" + e.getMessage(), ERR);
				// throws
			}

			LogManager.getIstance().scrivi("FacadeFiles - createFiles :" + newFile.getName() , RUN);
		} catch (IOException e) {
			new WishListrException(e,ERROR);
		}
		
		return newFile;
		
	}


	
	public void editFiles(Files file, Gift gift){
		// TODO Auto-generated method stub
	}


	
	public Files getFile(Gift gift) {

	Files file =null;
	try {
		try {
			file = fbr.getFileByGift(gift);
		} catch (WishlistrMessage e) {
			LogManager.getIstance().scrivi("FacadeGift - getFile :" + e.getMessage(), ERR);
			// throws
		}

		LogManager.getIstance().scrivi("FacadeFiles - getFile : Richiesta del file " + file.getName() , RUN);
	} catch (IOException e) {
		new WishListrException(e,ERROR);
	}
		return file;
	}


	
	public Files getSingleFile(int id_gift){
		
		Files file = null;
		try {
			try {
				file = fbr.getFileByIdGift(id_gift);
			} catch (WishlistrMessage e) {
				LogManager.getIstance().scrivi("FacadeGift - getSingleFile :" + e.getMessage(), ERR);
				// throws
			}
					
			LogManager.getIstance().scrivi("FacadeFiles - getSingleFile : Richiedi il file " + file.getName() , RUN);
		} catch (IOException e) {
			new WishListrException(e,ERROR);
		}
		return file;
	}
}
